<?php
if ( !defined( "IN_OP" ) )
{
    exit( "You can't access this file directly..." );
}
if ( ( $curruser['acl'] < 255 || $curruser['acl'] == 255 && $curruser['prev_id'] != 0 ) && !SubAccountRight( $curruser, 1 ) )
{
    diemsg( "你不是管理者！" );
}
$ui = new UI();
$lotto_id = intval( $_POST['lotto_id'] );
$bettype = 36;
$subid = intval( $_POST['subid'] );
$selectid = getvar( "select" ) == "" ? 0 : getvar( "select" );
$rate = $_POST['b61'] + 0;
$backs = $_POST['b62'] + 0;
$money = intval( $_POST['b63'] );
$account = $_POST['account'];
$subid_Arr = array( 21, 31, 41, 51);
if ( !in_array( $subid, $subid_Arr ) || $money == 0 )
{
    err( "错误的参数！" );
}
if ( $rate == 0 )
{
    err( "没有设置赔率！" );
}
if ( 15 < $backs )
{
    err( "不合理的退水！" );
}
$arnum = array();
$numcount = 0;
$i = 0;
while ( $i < 10 )
{
    if ( isset( $_POST["num_".$i] ) )
    {
        $arnum[$numcount] = $i;
        ++$numcount;
    }
    ++$i;
}
if ( $numcount < intval( substr( $subid, 0, 1 ) ) )
{
    err( "必须选择".intval( substr( $subid, 0, 1 ) )."个尾数！" );
}
else if ( intval( substr( $subid, 0, 1 ) ) < $numcount )
{
    err( "只能选择".intval( substr( $subid, 0, 1 ) )."个尾数！" );
}
asort( $arnum );
reset( $arnum );
$fields = array();
$fields['lotto_id'] = $lotto_id;
$fields['createtime'] = systime();
$fields['bettype'] = $bettype;
$fields['numbers'] = "'".$subid."|".implode( ",", $arnum )."'";
$fields['line_nums'] = "'".implode( ",", $arnum )."'";
$fields['amount'] = $money;
$fields['rate'] = $rate;
$fields['back'] = $backs;
$fields['account'] = "'".$account."'";
db_insert( "bet8", $fields );
echo "<p>走飞成功！</p>";
echo "<p><input type=button value='回上一页' onclick='history.back()'></p>";
echo "<script>";
echo "setTimeout(\"location.href='op.php?op=admin&fp=unow36&select={$selectid}'\",3000);";
echo "</script>";
?>